package com.hsl.study.exercise.day0207;


public class TwoSearch {
    public static int binarySearch(int [] arraySorted,int target) {
        int left = 0;
        int right = arraySorted.length -1 ;
        while (left <= right){
            int middle = (left + (right - left)/2);
            if (arraySorted[middle] == target){
                return middle;
            } else if (arraySorted[middle] < target){
                left = middle + 1;
            } else {
                right = middle - 1;
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        int[] arrays = new int[]{3,4,5,22,23,32,33,55,66,77};
        int target = 33;
        System.out.println(binarySearch(arrays,target));
    }
}
